package com.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 随机从List中取count个元素并返回新的List
 * 随机抽题
 */
public class RandomQuestion {

    public static <T> List<T> getRandomList(List paramList, int count) {
        if (paramList.size() < count) {
            return paramList;
        }
        Random random = new Random();
        List<Integer> tempList = new ArrayList<Integer>();
        List<T> newList = new ArrayList<T>();

        int temp;
        for (int i = 0; i < count; i++) {
            temp = random.nextInt(paramList.size());
            if (!tempList.contains(temp)) {
                tempList.add(temp);
                newList.add((T) paramList.get(temp));
            } else {
                i--;
            }
        }
        return newList;
    }
}
